package com.adong.test;

import com.adong.config.ApplicationConfig3;
import com.adong.pojo.Car;
import com.adong.pojo.Dream;
import com.adong.pojo.House;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * @author adong
 */

public class LifeCycleDemo {
    /**
     * init-method : 对象中的自定义的初始化方法" ;
     * destroy-method : 对象中自定义的销毁方法"
     * 的测试
     */
    @Test
    public void MethodDemo() {
        ApplicationContext applicationContext = new AnnotationConfigApplicationContext(ApplicationConfig3.class);
        Car car = applicationContext.getBean("car", Car.class);
    }

    /**
     * InitializingBean, DisposableBean实现测试
     */

    @Test
    public void Demo2() {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(ApplicationConfig3.class);
        House house = applicationContext.getBean("house", House.class);
        applicationContext.close();
    }

    /**
     * @PostConstruct : 在bean创建完成并属性赋值后来执行初始化方法.
     * @PreDestroy : 在容器销毁bean之前执行方法
     * 两个注解的测试方法
     */

    @Test
    public void Demo3() {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(ApplicationConfig3.class);
        Dream dream = applicationContext.getBean("dream", Dream.class);
        applicationContext.close();
    }
}
